Version Control (Git)

Git’s data model

Snapshots

<root> (tree)
|
+- foo (tree)
|  |
|  + bar.txt (blob, contents = "hello world")
|
+- baz.txt (blob, contents = "git is wonderful")

Modeling history: relating snapshots

// a file is a bunch of bytes
type blob = array<byte>

// a directory contains named files and directories
type tree = map<string, tree | blob>

// a commit has parents, metadata, and the top-level tree
type commit = struct {
  parents: array<commit>
  author: string
  message: string
  snapshot: tree
}

Objects and content-addressing

type object = blob | tree | commit
objects = map<string, object>

def store(object):
  id = sha1(object)
  objects[id] = object

def load(id):
  return objects[id]

References

references = map<string, string>

def update_reference(name, id):
  references[name] = id

def read_reference(name):
  return references[name]

def load_reference(name_or_id):
  if name_or_id in references:
	  return load(references[name_or_id])
  else:
	  return load(name_or_id)

Repositories

Staging area

Git command-line interface

Basics

Branching and merging

Remotes

Undo

Advanced Git

Miscellaneous

Resources